package wap;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TimeFormat {

	private static final Pattern PATTERN = Pattern.compile("(\\d+)/(\\w+)/(\\d+):(\\d+):(\\d+):(\\d+)");

	public static String format(String time) {
		StringBuffer sb = new StringBuffer();
		Matcher matcher = PATTERN.matcher(time);
		if (matcher.find()) {
			sb.append(matcher.group(3));// 年
			sb.append("-");
			sb.append(changeMonth(matcher.group(2)));// 月
			sb.append("-");
			sb.append(matcher.group(1));// 日
			sb.append(" ");
			sb.append(matcher.group(4));// 时
			sb.append(":");
			sb.append(matcher.group(5));// 分
			sb.append(":");
			sb.append(matcher.group(6));// 秒
			return sb.toString();
		}
		return time;
	}

	private static String changeMonth(String month) {
		if ("Jan".equals(month))
			return "01";
		else if ("Feb".equals(month))
			return "02";
		else if ("Mar".equals(month))
			return "03";
		else if ("Apr".equals(month))
			return "04";
		else if ("May".equals(month))
			return "05";
		else if ("Jun".equals(month))
			return "06";
		else if ("Jul".equals(month))
			return "07";
		else if ("Aug".equals(month))
			return "08";
		else if ("Sep".equals(month))
			return "09";
		else if ("Oct".equals(month))
			return "10";
		else if ("Nov".equals(month))
			return "11";
		else if ("Dec".equals(month))
			return "12";
		else
			return month;
	}

	public static void main(String[] args) {
		System.out.println(format("20/Sep/2014:23:59:55 +0800"));
	}
}
